package pers.gxm.visitor;

import java.util.ArrayList;
import java.util.Iterator;

public class Directory extends Entry{
    private String name;
    private ArrayList<Entry> dirList = new ArrayList<>();

    public Directory(String name){
        this.name = name;
    }
    @Override
    public void accept(Visitor v) {
        v.visit(this);
    }
    @Override
    public String getName() {
        return name;
    }

    @Override
    public int getSize() {
        int size = 0;
        Iterator<Entry> iterator = dirList.iterator();
        while(iterator.hasNext()){
            Entry next = iterator.next();
            size += next.getSize();
        }
        return size;
    }

    @Override
    public Entry add(Entry entry) throws FileTreatmentException {
        dirList.add(entry);
//        返回添加后的Entry
        return this;
    }

    @Override
    public Iterator<Entry> iterator() throws FileTreatmentException {
        return dirList.iterator();
    }
}
